<?php
namespace App\Models;

use App\Models\Model;

class DictionaryItem extends Model
{
    protected $table = 'dictionary_item'; 

    public function children()
    {
        return $this->hasMany(self::class, 'parent_id', 'id')->select('id', 'code', 'item_name', 'parent_id', 'item_value');
    }

    /**
     * 获取字典
     * @author lxy
     * @datetime 2023-02-24
     * @param $item array 字典code['SUBJECT','LEVEL','award_level']
     * @return array
     */
    public static function getDictionaryItem($item){
        return self::whereIn('id',$item)
            ->select('item_order as order','id as optionId','parent_id as parentId','item_value as selectKey','item_name as selectValue')
            ->orderBy('item_order','asc')
            ->get()
            ->toArray();
    }
    
}

?>